﻿/*
    This stored procedure adds a new Test Server into the database.

    It uses the default paths (those used by the Test Server Installer) for both
    the configFilesDirectory and the loadSyncApplicationPath columns.
    
    It does not fill the mefComponentRootDirectory column as this column is
    forward compatibility only and is not used yet.

    The last parameter is an output parameter storing the ID of the added Test Server.
    It's an optionnal parameter because a user calling this procedure does not care about
    the new ID but some code calling this procedure could care.

*/

CREATE PROCEDURE [Admin].[sp_z4s_add_test_server]
      @param_testServerName NVARCHAR(255)
    , @param_testServerHostName NVARCHAR(255)
    , @param_testServerWcfConfigSectionName NVARCHAR(255)
    , @param_testServerHostInstallDirectory NVARCHAR(450)
    , @output_newTestServerId UNIQUEIDENTIFIER = NULL OUT
AS

    SET @output_newTestServerId = NEWID()

    INSERT INTO Admin.testServer
        ( testServer_id
        , testServer_name
        , testServer_hostName
        , testServer_wcfConfigSectionName
        , testServer_configFilesDirectory
        , testServer_loadSyncApplicationPath
        , testServer_mefComponentRootDirectory )
    VALUES
        ( @output_newTestServerId
        , @param_testServerName
        , @param_testServerHostName
        , @param_testServerWcfConfigSectionName
        , @param_testServerHostInstallDirectory + '\ClientTestSessionDescriptors'
        , @param_testServerHostInstallDirectory + '\Zen4SyncClient\Zen4SyncClient.exe'
        , NULL);

RETURN 0